<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ attribute name="input" type="java.lang.String" required="true" description="输入框"%>
<%@ attribute name="mime" type="java.lang.String" required="true" description="image"%>
<%@ attribute name="maxWidth" type="java.lang.String" required="false" description="最大宽度"%>
<%@ attribute name="maxHeight" type="java.lang.String" required="false" description="最大高度"%>
<%@ attribute name="userId" type="java.lang.String" required="true" description="用户ID"%>
<ol id="${input}Preview"></ol>
<a href="javascript:" onclick="${input}FinderOpen();" class="btn">选择</a>
&nbsp;
<a href="javascript:" onclick="${input}DelAll();" class="btn">清除</a>
<script type="text/javascript">
	function ${input}FinderOpen () {
	    var url = "${ctxStatic}/elfinder/elfinderSelect.html?fileServer=${fileServer}&userId=${userId}&mime=${mime}";
	    windowOpen (url, "文件管理", 1000, 500);
    }
	function SelectAction(fileUrl){
		$("#${input}").val(fileUrl);
		${input}Preview();
	}
	function ${input}Del(obj){
		var url = $(obj).prev().attr("url");
		$("#${input}").val($("#${input}").val().replace("|"+url,"","").replace(url+"|","","").replace(url,"",""));
		${input}Preview();
	}
    function ${input}DelAll () {
	    $ ("#${input}").val ("");
	    ${input}Preview ();
    }
    function ${input}Preview () {
	    var li, urls = $ ("#${input}").val ().split ("|");
	    $ ("#${input}Preview").children ().remove ();
	    for (var i = 0; i < urls.length; i++){
		    if (urls[i] != ""){
			    li = "<li><img src=\""+ urls[i]+ "\" url=\""+ urls[i]+ "\" style=\"max-width:${empty maxWidth ? 200 : maxWidth}px;max-height:${empty maxHeight ? 200 : maxHeight}px;_height:${empty maxHeight ? 200 : maxHeight}px;border:0;padding:3px;\">";
			    li += "&nbsp;&nbsp;<a href=\"javascript:\" onclick=\"${input}Del(this);\">×</a></li>";
			    $ ("#${input}Preview").append (li);
		    }
	    }
	    if ($ ("#${input}Preview").text () == ""){
		    $ ("#${input}Preview").html ("<li style='list-style:none;padding-top:5px;'>无</li>");
	    }
    }
    ${input}Preview ();
</script>